<?php

// 投票支持参赛选手
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

require_once libfile('function/database');
require_once libfile('function/vote');
require_once libfile('function/date');

$aid = intval(getgpc('aid')); // 活动唯一标识
$uid = intval(getgpc('uid')); // 参赛选手唯一标识
$mid = $_G['uid'];    // 投票会员的唯一标识.
// 自己不能给自己投票
if ($mid  == $uid) {
	$message = lang('bid/template', 'cant_not_vote_self');
	showmessage($message, '', array(), array('showmsg' => true, 'alert' => 'info'));
}

if (!(empty($aid) || empty($uid))) {
	$activity = get_activity($aid);
	if ($mid){
		// 检查会员是否用户投票所需的要得金币数量。
		if ($activity['ticket_fee'] <= 0 || ($activity['ticket_fee'] > 0 && get_gold_coin() >= $activity['ticket_fee'])) {
			list($result, $total_tickets, $tickets_member_day) = vote_member_tickets($mid, $aid, $uid);
			if (0 != $result) {
				$user = get_user($uid);
				$message = lang('bid/template', 'member_vote_ticket_error', array('max_tickets_member' => $activity['max_tickets_member'],
					'user_name' => $user['user_name'], 'total_tickets' => $total_tickets, 'max_tickets_member_day' => $activity['max_tickets_member_day'], 'tickets_member_day' => $tickets_member_day));
				showmessage($message, '', array(), array('showmsg' => true, 'alert' => 'error'));
			}
		}
		else {
			$message = lang('bid/template', 'not_enough_ticket_fee', array('ticket_fee' => $activity['ticket_fee'],
				'user_gold_coin' => get_gold_coin()));
			showmessage($message, '', array(), array('showmsg' => true, 'alert' => 'info'));
		}
	}
	else {
		// 非登录用户投票
		$ip = $_G['clientip'];
		list($result, $total_tickets, $tickets_ip_day) = vote_ip_tickets($ip, $aid, $uid);
		if (0 != $result) {
			$user = get_user($uid);
			$message = lang('bid/template', 'ip_vote_ticket_error', array('max_tickets_ip' => $activity['max_tickets_ip'],
				'user_name' => $user['user_name'], 'total_tickets' => $total_tickets, 'max_tickets_ip_day' => $activity['max_tickets_ip_day'], 'tickets_ip_day' => $tickets_ip_day));
			showmessage($message, '', array(), array('showmsg' => true, 'alert' => 'error'));
		}
	}
}
else {

}

require_once 'user.php';
?>